﻿//-----------------------------------------------------------------------
// <copyright file="All.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the All class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.Tuples
{
    using System;

    /// <summary>
    /// Represents a special key value used to store all tuples.   It is treated as a type of null value.
    /// This class is used during tuple member evaluation.
    /// </summary>
    public class All : IComparable
    {
        #region IComparable Members

        /// <summary>
        /// Tests to see if two All objects provided are equal.
        /// </summary>
        /// <param name="allA">First All to be evaluated.</param>
        /// <param name="allB">Second All to be evaluated.</param>
        /// <returns>True if equal.  Otherwise false.</returns>
        public static bool operator ==(All allA, All allB)
        {
            return allA.Equals(allB);
        }

        /// <summary>
        /// Tests to see if two All objects provided are not equal.
        /// </summary>
        /// <param name="allA">First All to be evaluated.</param>
        /// <param name="allB">Second All to be evaluated.</param>
        /// <returns>True if unequal.  Otherwise false.</returns>
        public static bool operator !=(All allA, All allB)
        {
            return !allA.Equals(allB);
        }
        
        /// <summary>
        /// LT operator.
        /// </summary>
        /// <param name="allA">First All to be evaluated.</param>
        /// <param name="allB">Second All to be evaluated.</param>
        /// <returns>
        /// True or false.   For two different Alls, this is arbitary,
        /// as Alls never equate.
        /// </returns>
        public static bool operator >(All allA, All allB)
        {
            return allA.GetHashCode() > allB.GetHashCode();
        }

        /// <summary>
        /// GT operator.
        /// </summary>
        /// <param name="allA">First All to be evakuated.</param>
        /// <param name="allB">Second All to be evaluated.</param>
        /// <returns>
        /// True or false.   For two different Alls, this is arbitary,
        /// as Alls never equate.
        /// </returns>
        public static bool operator <(All allA, All allB)
        {
            return allA.GetHashCode() < allB.GetHashCode();
        }

        /// <summary>
        /// Camprison method.
        /// </summary>
        /// <param name="obj">Object to be compared.</param>
        /// <returns>Returns 0 if the compared object is an All.   Otherwise, always return a negative number.</returns>
        public int CompareTo(object obj)
        {
            return (obj is Null) ? 0 : -1;
        }

        /// <summary>
        /// Tests to see if the object provided is equal to this All.
        /// </summary>
        /// <param name="obj">The object to compare.</param>
        /// <returns>True if equal, otherwise false.</returns>
        public override bool Equals(object obj)
        {
            // Because All is a special type of null, two All objects never match
            return false;
        }

        /// <summary>
        /// Returns the hashcode for the All.
        /// </summary>
        /// <returns>A hashcode.</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #endregion
    }
}
